;
(function ($, w) {
	var winHei = $(w).height()
	var loadFn = function () {
		var $conLis = $('[_load]')
		$conLis.each(function (i, v) {
			var scrollTop = $(w).scrollTop()
			var $v = $(v)
			if ($conLis.filter('_load') == 0) $(w).off('scroll.z')
			if (winHei + scrollTop > $v.offset().top) {
				$v.addClass('active')
				$(this).removeAttr('_load')
			}
		})
	}
	$(w).on('scroll.z load', loadFn)
})(jQuery, window)

$(function () {
	//fixed nav bind on jquery
	$.fn.navFixed = function () {
		var $_this = $(this),
			$_this_prev_marginBottom = parseInt(
				$_this
				.prev()
				.css('margin-bottom')
				.substring(0, $_this.prev().css('margin-bottom').length - 2)
			),
			$_this_next_marginTop = parseInt(
				$_this
				.next()
				.css('margin-top')
				.substring(0, $_this.next().css('margin-top').length - 2)
			),
			_topPosition = $(document).scrollTop(),
			_navPosition = $_this.prev().find('img').height()

		_if()

		$(document).scroll(function () {
			_topPosition = $(document).scrollTop()
			_if()
		})

		$(window).resize(function () {
			_navPosition = $_this.prev().find('img').height()
			_if()
		})

		function _if() {
			var width = $(window).width()
			// console.log(_topPosition,_navPosition)
			if (_navPosition > 21 && _topPosition >= _navPosition) {
				$_this.css('position', 'fixed')
				if (width <= 1024) {
					$_this.css('top', '0')
				}
				$_this
					.next()
					.css(
						'margin-top',
						$_this_prev_marginBottom +
						$_this.outerHeight() +
						$_this_next_marginTop +
						'px'
					)
			} else {
				$_this.css('position', 'relative')
				if (width <= 1024) {
					$_this.css('top', '0')
				}
				$_this.next().css('margin-top', $_this_next_marginTop + 'px')
			}
		}
	}

	$('.menuContainer>ul>li').on('click', function () {
		var itemchild = $(this).find('>.child')
		if (itemchild.length > 0) {
			itemchild.slideToggle()
		}
	})
	$('.menuContainer>ul>li>.child li').on('click', function (event) {
		event.stopPropagation()
		var itemchild = $(this).find('>.child')
		if (itemchild.length > 0) {
			itemchild.slideToggle()
		}
	})

	function initBannerHeight() {
		var screenHeight = document.documentElement.clientHeight
		var headerEl = $('.header')
		var headerHeight = headerEl.height()
		var headerMobole = $('.menu_mobile').outerHeight()
		headerHeight = headerHeight || headerMobole
		if (
			headerEl.css('position') !== 'absolute' &&
			headerEl.css('position') !== 'fixed'
		) {
			$('.home.banner').height(screenHeight - headerHeight)
		}
	}

	// window.addEventListener('DOMContentLoaded',function(){
	//     initBannerHeight();
	// });

	$('.form input').focus(function () {
		$(this).css('border-bottom', '1px solid #147cd2')
	})

	$('.form input').blur(function () {
		$(this).css('border-bottom', '1px solid rgba(255, 255, 255, 0.5)')
	})

	$('.nav-button').click(function () {
		$(this).toggleClass('active')
		$('.menuContainer').slideToggle()
		var top = $(document).scrollTop()
		if ($(this).hasClass('active')) {
			$(document).on('scroll.unable', function (e) {
				$(document).scrollTop(top)
			})
		} else {
			$(document).unbind('scroll.unable')
		}
	})

	$('.rightBar .toTop').on('click', function () {
		$('html,body').animate({
				scrollTop: 0,
			},
			800
		)
	})

	$('.mobile-common-fixed-menu .toTop').on('click', function () {
		$('html,body').animate({
				scrollTop: 0,
			},
			800
		)
	})

	$('.loadingContainer').hide()
})

var numSetAnimation = function (num, selector, timeOut, intNumS) {
	var max = num,
		o = selector
	var intNum = intNumS

	intNum = Number(intNum)
	var setTime = (timeOut * intNum) / num
	var num_now = 0
	// console.log(num_now);
	o.innerText = num_now.toFixed(0)

	var s = setInterval(function () {
		num_now += intNum
		if (num_now >= max) {
			clearInterval(s)
			num_now = max
		}
		num_now = +num_now
		o.innerText = num_now.toFixed(0) * 1
	}, setTime)
}
var myFunction = function () {
	if (scrollT($('.scroll-num'))) {
		for (var i = 0; i < $('.num').length; i++) {
			var itemNode = $('.num')[i]
			var num = itemNode.getAttribute('data-target');
			if (num) {
				var speed = num / 100
				numSetAnimation(num, itemNode, 2000, speed)
			}
		}
		window.removeEventListener('scroll', myFunction)
	}
}
window.addEventListener('scroll', myFunction)

function getUrlParam(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)') //鏋勯€犱竴涓惈鏈夌洰鏍囧弬鏁扮殑姝ｅ垯琛ㄨ揪寮忓璞�
	var r = window.location.search.substr(1).match(reg) //鍖归厤鐩爣鍙傛暟
	if (r != null) return decodeURIComponent(r[2])
	return null //杩斿洖鍙傛暟鍊�
}

function dateFormat(date, fmt) {
	var time = new Date(date);
	//console.log(time.getMonth(), new Date().getTime())
	var o = {
		'M+': time.getMonth() + 1, //鏈堜唤
		'd+': time.getDate(), //鏃�
		'h+': time.getHours(), //灏忔椂
		'm+': time.getMinutes(), //鍒�
		's+': time.getSeconds(), //绉�
		'q+': Math.floor((time.getMonth() + 3) / 3), //瀛ｅ害
		S: time.getMilliseconds(), //姣
	}
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(
			RegExp.$1,
			(time.getFullYear() + '').substr(4 - RegExp.$1.length)
		)
	for (var k in o)
		if (new RegExp('(' + k + ')').test(fmt))
			fmt = fmt.replace(
				RegExp.$1,
				RegExp.$1.length == 1 ?
				o[k] :
				('00' + o[k]).substr(('' + o[k]).length)
			)
	return fmt
}

function IsPC() {
	var userAgentInfo = navigator.userAgent
	var Agents = new Array(
		'Android',
		'iPhone',
		'SymbianOS',
		'Windows Phone',
		'iPad',
		'iPod'
	)
	var flag = true
	for (var v = 0; v < Agents.length; v++) {
		if (userAgentInfo.indexOf(Agents[v]) > 0) {
			flag = false
			break
		}
	}
	return flag
}

function validatePhone(value) {
	var length = value.length
	var mobile = /^1\d{10}$/
	return length == 11 && mobile.test(value)
}

function getUrlParam(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)') //鏋勯€犱竴涓惈鏈夌洰鏍囧弬鏁扮殑姝ｅ垯琛ㄨ揪寮忓璞�
	var r = window.location.search.substr(1).match(reg) //鍖归厤鐩爣鍙傛暟
	if (r != null) return decodeURIComponent(r[2])
	return null //杩斿洖鍙傛暟鍊�
}

function textareaImgDeal(selector) {
	var textareaImg = $(selector).find("img");
	for (var i = 0; i < textareaImg.length; i++) {
		var containerWidth = $(selector).width();
		var itemImgWidth = $(textareaImg[i]).width();
		//console.log(itemImgWidth,containerWidth)
		if (itemImgWidth > containerWidth) {
			$(textareaImg[i]).css({
				width: '100%'
			})
		}
	}
}
textareaImgDeal(".textAreaContainer");

function setLangFn() {
	var initLang = window.sessionStorage.getItem('lang')
	if (!initLang || initLang == 'zh') {
		$('.lang-zh').css('display', 'block')
		$('.lang-en').css('display', 'none')
	} else {
		$('.lang-zh').css('display', 'none')
		$('.lang-en').css('display', 'block')
	}
}
//  var baseUrl = 'http://47.116.64.113:81/'
//var baseUrl = 'http://192.168.0.114:8080/'